using UnityEngine;
using System.Collections;
#if !UNITY_FLASH && !UNITY_WEBPLAYER
using System.IO;
#endif
using System.Text;


public class LCFileManager{
	
	static public bool DirectoryExists(string path){
		
#if !UNITY_FLASH && !UNITY_WEBPLAYER 		
		return Directory.Exists(path);
#else
		return false;
#endif		
	}
	
	static public void DirectoryCreateDirectory(string path){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		Directory.CreateDirectory(path);
#endif
	}
	
	static public void FileWriteAllBytes(string path, byte[] contents){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		File.WriteAllBytes( path, contents );
#endif
	}	
	
	static public bool FileExists(string path){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		return File.Exists(path);
#else		
		return false;
#endif
	}		
	
	static public void FileWriteAllText(string path, string contents){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		File.WriteAllText(path,contents);	
#endif
	}
	
	static public string[] FileReadAllLine(string path){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		return File.ReadAllLines(path);	
#endif
	}

    static public string FileReadAllText(string path)
    {
#if !UNITY_FLASH && !UNITY_WEBPLAYER
        return File.ReadAllText(path);
#endif
    }
	
	static public byte[] FileReadAllBytes(string path){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		return File.ReadAllBytes( path );
#else
		return null;
#endif		
	}				
	
	static public byte[] FileOpenRead(string path){
		byte[] buffer = null;
#if !UNITY_FLASH && !UNITY_WEBPLAYER
		FileStream fileStream = File.Open( path, FileMode.Open );
		buffer = new byte[fileStream.Length];
		fileStream.Read(buffer, 0, buffer.Length);	
		fileStream.Close();
#endif		
		return buffer;

	}	
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
	static public BinaryWriter GetBinaryWriter(string path){
		BinaryWriter result = null;
	
		result = new BinaryWriter( File.Open( path, FileMode.Create), Encoding.UTF8 );
		return result;

	}
#endif		

#if !UNITY_FLASH && !UNITY_WEBPLAYER
	static public BinaryReader GetBinaryReader(string path){
		BinaryReader result = null;
		result = new BinaryReader( File.Open(path, FileMode.Open) );
		return result;
	}
#endif

#if !UNITY_FLASH && !UNITY_WEBPLAYER			
	static public TextWriter GetStreamWriter(string path){
		TextWriter result = null;
		result = new StreamWriter( File.Open( path, FileMode.Create), Encoding.UTF8 );
		return result;
	}	
#endif

#if !UNITY_FLASH && !UNITY_WEBPLAYER			
	static public TextReader GetStreamReader(string path){
		TextReader result = null;
		result = new StreamReader( File.Open(path, FileMode.Open) );
		return result;
	}	
#endif
	
	static public void FileDelete(string path){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		if( FileExists(path) )
			File.Delete(path);
#endif
	}
	
	static public void WriteBinaryByteArray(string path, ArrayList byteArray_List){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		BinaryWriter BW = LCFileManager.GetBinaryWriter(path);
		foreach(byte[] unit in byteArray_List){
			BW.Write( unit );
		}
		BW.Close();
#endif
	}
	
	static public void WriteBinaryByteArray(string path, byte[] byteArray ){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		BinaryWriter BW = LCFileManager.GetBinaryWriter(path);
		BW.Write( byteArray );
		BW.Close();
#endif
	}	
	
	static public void WriteTextObject(string path, object obj){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		TextWriter textWriter = LCFileManager.GetStreamWriter( path );
		textWriter.Write( obj );
		textWriter.Close();
#endif
	}
	
	static public void DeleteFile(string path){
#if !UNITY_FLASH && !UNITY_WEBPLAYER		
		File.Delete(path);
#endif
	}
}

//Application.OpenURL("mailto:yesyoucan@hotmail.com?subject=Email&body=from Unity");
